#!/bin/sh
#参考：https://blog.csdn.net/windfromthesouth/article/details/72961525
#命令：
#下载完成后，进入gitstats目录，将gitstats拷贝为gitstats.py文件
#$ cp gitstats gitstats.py
#然后执行统计命令
#$ python gitstats.py  ../gst-test/ ./test
#../gst-test/ 为工程所在目录
#./test 为结果文件目录
#完成后，进入test目录，双击index.html文件查看统计结果
#计算的是当前分支中的提交量
if [ "x$1" == "x" ]; then 
    echo input is null and you can select follows:
    echo "AndroidReceiver "
    echo "AndroidSender   "
    echo "AppleSenderApp  "
    echo "AppleSenderSDK  "
    echo "SDK             "
    echo "source          "
    echo "LBCloud         "
    echo "LBCloud-AD      "
    echo "LBCloud-Auth    "
    echo "LBCloud-Common  "
    echo "LBCloud-Data    "
    echo "LBCloud-Go      "
    echo "LBCloud-Pay     "
    echo "LBCloud-Plat    "
    echo "ToB-PP          "
    echo "ToB-PP-App      "
    echo "ToB-RSDK        "
    echo "ToB-Win-App     "
    echo "ToB-Win-Sdk     "
    echo "all"
	echo "report_data"
    exit 1
fi
echo genarate $1 report
cur_path=`pwd`
var_list="AndroidReceiver AndroidSender AppleSenderApp AppleSenderSDK SDK source LBCloud LBCloud-AD LBCloud-Auth LBCloud-Common LBCloud-Data \
LBCloud-Go LBCloud-Pay LBCloud-Plat ToB-PP ToB-PP-App ToB-RSDK ToB-Win-App ToB-Win-Sdk"
if [ "$1" == "all" ]; then
for var_m in $var_list
    do 
        echo report path is $cur_path/report/$var_m
        python gitstats.py ../$var_m ./report/$var_m
        echo --------$var_m done-------------------
    done
else
    if [ "$1" != "report_data" ]; then 
        echo report path is $cur_path/report/$1
        python gitstats.py ../$1 ./report/$1
	fi 
fi 

if [ "$1" == "report_data" ]; then
    echo  > report/data.txt
	echo > report/total_lines.txt
	echo > report/added_lines.txt
	echo > report/removed_lines.txt
	echo > report/total_commits.txt
for var_r in $var_list
    do 
    fit_string=`cat report/$var_r/index.html |grep "Total Lines of Code" |awk -F "Total Lines of Code" '{print $2}' |awk -F "Authors" '{print $1}'`
    #echo $var_r: fit_string=$fit_string
    total_lines_string=`echo $fit_string |awk -F "dd>" '{print $2}'|awk -F "<" '{print $1}'`
    total_lines=`echo $total_lines_string |awk -F "(" '{print $1}' `
    total_add_lines=`echo $total_lines_string |awk -F "added" '{print $1}' |awk -F "(" '{print $2}'`
    total_remove_lines=`echo $total_lines_string |awk -F "removed" '{print $1}' |awk -F ", " '{print $2}'`
    total_commit=`echo $fit_string |awk -F "Total Commits" '{print $2}' |awk -F "dd>" '{print $2}' |awk -F "(" '{print $1}' `
    echo $total_lines   $total_add_lines   $total_remove_lines   $total_commit >> report/data.txt
	echo $total_lines >> report/total_lines.txt
	echo $total_add_lines >> report/added_lines.txt
	echo $total_remove_lines >> report/removed_lines.txt
	echo $total_commit >> report/total_commits.txt 
    echo 
    done
	
fi


